package org.ruanjj.lettercombinations;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class Solution1 {
   public final static List<String> MAPPING = List.of("","","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz");
    public List<String> letterCombinations(String digits) {
       List<String> result = new ArrayList<>();
       if(digits.isBlank()){
           return result;
       }
       int i = 0;
       StringBuilder path = new StringBuilder();
       dg(i,digits,result,path);
       return result;
    }

    private void dg(int index,String digits,List<String> result, StringBuilder path){
        if(index == digits.length()){
            result.add(path.toString());
            return;
        }
        String letterString = MAPPING.get(digits.charAt(index) - '0');
        for(Character c: letterString.toCharArray()){
            path.append(c);
            dg(index+1,digits,result,path);
            path.deleteCharAt(path.length()-1);
        }
    }
}
